Lumen Programming Guide by Paul Redmond
Author:Paul Redmond
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
The constructor method type-hints the FractalResponse argument that the service container will resolve automatically when initializing the controller. The item and collection methods are pass-through methods to the FractalResponse service. You could make the methods more generic like respondWithItem and take care of the response, but what you have is good enough for now. You can refactor when you sense duplication and brittle code.
Let’s try your first integration with the BooksController. Be sure to add use App\Transformer\BookTransformer; and extends Controller to start using the base application controller at the top of app/Http/Controllers/BooksController.php (Listing 7-56).
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Book;
6 use Illuminate\Http\Request;
7 use App\Transformer\BookTransformer;
8 use Illuminate\Database\Eloquent\ModelNotFoundException;
9
10 /**
11 * Class BooksController
12 * @package App\Http\Controllers
13 */
14 class BooksController extends Controller
15 {
16 /**
17 * GET /books
18 * @return array
19 */
20 public function index()
21 {
22 return $this->collection(Book::all(), new BookTransformer());
23 }
24 // ...
25 }
Listing 7-56.Using the FractalResponse Service in the BooksController
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7808)
Grails in Action by Glen Smith Peter Ledbrook(7719)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6828)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6828)
Running Windows Containers on AWS by Marcio Morales(6354)
Kotlin in Action by Dmitry Jemerov(5090)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(5064)
Combating Crime on the Dark Web by Nearchos Nearchou(4640)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4603)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4437)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4330)
The Age of Surveillance Capitalism by Shoshana Zuboff(3979)
Python for Security and Networking - Third Edition by José Manuel Ortega(3890)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3550)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3528)
Learn Wireshark by Lisa Bock(3520)
Mastering Python for Networking and Security by José Manuel Ortega(3376)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3355)
Blockchain Basics by Daniel Drescher(3324)
